{template 'web/_header'}
<ul class="nav nav-tabs">
    <li {if ($_GPC['p'] == 'list' || $_GPC['p'] == '') && ($_GPC['op'] == '' || $_GPC['op'] == 'display')}class="active"{/if}><a href="{php echo $this->createWebUrl('saoyue/list')}">扫码领余额</a></li>
    <li {if $_GPC['p'] == 'list' && $_GPC['op'] == 'post'}class="active"{/if}><a href="{php echo $this->createWebUrl('saoyue/list',array('op'=>'post'))}">添加扫码领余额</a></li>
    {if $_GPC['op'] == 'qrcode'}<li class="active"><a href="javascript:;">批量生成二维码</a></li>{/if}
    <li {if $_GPC['op'] == 'download'}class="active"{/if}><a href="{php echo $this->createWebUrl('saoyue/list',array('op'=>'download'))}">下载二维码</a></li>
</ul>
{if $operation == 'display'}
     <form action="" method="post">
<div class="panel panel-default">
    <div class="panel-body table-responsive">
        <table class="table table-hover">
            <thead class="navbar-inner">
                <tr>
                    <th style="width:5%">ID</th>
                    <th>标题</th>
                    <th style='width:40%'>链接</th>
                    <th>金额</th>
                    <th style='width:10%'>使用期限</th>
                    <th>最多领取次数</th>
                    <th>每人最多领取次数</th>
                    <th>已领次数</th>
                    <th>状态</th>
                    <th style='width:10%'>操作</th>
                    <th style='text-align:center;width:10%'>二维码</th>
                </tr>
            </thead>
            <tbody>
                {loop $list $row}
                <tr>
                    <td style="width:5%">{$row['id']}</td>
                    <td style='width:5%'>{$row['title']}</td>
                    <td style='width:40%'>{$row['lianjie']}</td>
                    <td>{$row['num']}</td>
                    <td style='width:10%'>{$row['datelimit']}</td>
                    <td>{$row['limit']}</td>
                    <td>{$row['perlimit']}</td>
                    <td>{$row['record']}</td>
                    <td style='width:5%'>
                    	{if $row['status']==1}
                        <span class='label label-success'>显示</span>
                        {else}
                        <span class='label label-danger'>隐藏</span>
                        {/if}
                    </td>
                    <td style="text-align:left;width:10%">
                        {ifp 'saoyue.list.view|saoyue.list.edit'}<a href="{php echo $this->createWebUrl('saoyue/list', array('op' => 'post', 'id' => $row['id']))}" class="btn btn-default btn-sm" data-toggle="tooltip" data-placement="top" title="{ifp 'saoyue.list.edit'}修改{else}查看{/if}"><i class="fa fa-edit"></i></a>{/if}
                        {ifp 'saoyue.list.delete'}
                        <a href="{php echo $this->createWebUrl('saoyue/list', array('op' => 'delete', 'id' => $row['id']))}" 
                        	class="btn btn-default btn-sm" onclick="return confirm('确认删除此扫码领余额?')" title="删除"><i class="fa fa-times"></i>
                       	</a>
                       	{/if}
                       	<a href="{php echo $this->createWebUrl('saoyue/list', array('op' => 'record', 'id' => $row['id']))}" class="btn btn-default btn-sm">
                       	兑换记录</a>
                    </td>
                    <td style="text-align:center;width:10%">
                    <a href="{php echo $this->createWebUrl('saoyue/list',array('op'=>'qrcode', 'id' => $row['id']))}" class="btn btn-default btn-sm">批量生成</a></td>
                </tr>
                {/loop}
                <tr>
                    <td colspan='9'>
                    {ifp 'saoyue.list.add'}
                    	<a class='btn btn-default' href="{php echo $this->createWebUrl('saoyue/list',array('op'=>'post'))}"><i class='fa fa-plus'></i> 添加扫码领余额</a>
                    {/if}
                    </td>
                </tr>
            </tbody>
        </table>
        {$pager}
    </div>
</div>
</form>
<script>
    require(['bootstrap'], function ($) {
        $('.btn').hover(function () {
            $(this).tooltip('show');
        }, function () {
            $(this).tooltip('hide');
        });
    });
    
</script>

{elseif $operation == 'post'}

<div class="main">
    <form     {ife 'saoyue.list' $saoyue}action="" method="post"{/if} class="form-horizontal form" enctype="multipart/form-data" onsubmit='return formcheck()'>
        <input type="hidden" name="id" value="{$saoyue['id']}" />
        <div class="panel panel-default">
            <div class="panel-heading">
                扫码领余额设置
            </div>
            <div class="panel-body">
            	{if $id}
            	<div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">扫码领余额链接</label>
                    <div class="col-sm-9 col-xs-12">
                    <div class="form-control" style="border:0">http://wx.lanxuevip.com/app/index.php?i=5&c=entry&do=saoyue&m=ewei_shop&id={$id}</div>
                    </div>
                </div>
                {/if}
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style="color:red">*</span>扫码领余额标题</label>
                    <div class="col-sm-9 col-xs-12">
                            {ife 'saoyue.list' $saoyue}
                        <input type="text" id='title' name="title" class="form-control" value="{$saoyue['title']}" />
                           {else}
                        <div class='form-control-static'>{$saoyue['title']}</div>
                        {/if}
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style="color:red">*</span>赠送余额数量</label>
                    <div class="col-sm-9 col-xs-12">
                            {ife 'saoyue.list' $saoyue}
                        <input type="text" id='num' name="num" class="form-control" value="{$saoyue['num']}" />
                           {else}
                        <div class='form-control-static'>{$saoyue['num']}</div>
                        {/if}
                        <span class="help-block">请填写整数</span>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style="color:red">*</span>最多赠送次数</label>
                    <div class="col-sm-9 col-xs-12">
                            {ife 'saoyue.list' $saoyue}
                        <input type="text" id='limit' name="limit" class="form-control" value="{$saoyue['limit']}" />
                           {else}
                        <div class='form-control-static'>{$saoyue['limit']}</div>
                        {/if}
                        <span class="help-block">请填写整数</span>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">每人最多赠送次数</label>
                    <div class="col-sm-9 col-xs-12">
                            {ife 'saoyue.list' $saoyue}
                        <input type="text" id='perlimit' name="perlimit" class="form-control" value="{$saoyue['perlimit']}" />
                           {else}
                        <div class='form-control-static'>{$saoyue['perlimit']}</div>
                        {/if}
                        <span class="help-block">请填写整数,0或不填代表不限制领取次数</span>
                    </div>
                </div>
                <div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">使用期限</label>
					<div class="col-sm-9 col-xs-12">
						{php echo tpl_form_field_daterange('datelimit', array('starttime' => date('Y-m-d', $saoyue['starttime']),'endtime' => date('Y-m-d', $saoyue['endtime'])), '')}
					</div>
				</div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">是否显示</label>
                    <div class="col-sm-9 col-xs-12">
                            {ife 'saoyue.list' $saoyue}
                        <label class='radio-inline'>
                            <input type='radio' name='status' value=1' {if $saoyue['status']==1}checked{/if} /> 是
                        </label>
                        <label class='radio-inline'>
                            <input type='radio' name='status' value=0' {if $saoyue['status']==0}checked{/if} /> 否
                        </label>
                            {else}
                             <div class='form-control-static'>{if empty($saoyue['status'])}否{else}是{/if}</div>
                            {/if}
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">跳转链接地址</label>
                    <div class="col-sm-9 col-xs-12">
                            {ife 'saoyue.list' $saoyue}
                        <input type="text" id='link' name="link" class="form-control" value="{$saoyue['link']}" />
                           {else}
                        <div class='form-control-static'>{$saoyue['link']}</div>
                        {/if}
                    </div>
                </div>
                 <div class="form-group"></div>
            <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label"></label>
                    <div class="col-sm-9 col-xs-12">
                        {ife 'saoyue.list' $saoyue}
                            <input type="submit" name="submit" value="提交" class="btn btn-primary col-lg-1"  />
                            <input type="hidden" name="token" value="{$_W['token']}" />
                        {/if}
                       <input type="button" name="back" onclick='history.back()' {ifp 'saoyue.list.add|saoyue.list.edit'}style='margin-left:10px;'{/if} value="返回列表" class="btn btn-default" />
                    </div>
            </div>
                
                
            </div>
        </div>
      
    </form>
</div>

<script language='javascript'>
    function formcheck() {
        if ($("#title").isEmpty()) {
            Tip.focus("title", "请填写扫码领奖标题!");
            return false;
        }
        if ($("#num").isEmpty()) {
            Tip.focus("num", "请填写赠送余额数量!");
            return false;
        }
        if ($("#limit").isEmpty()) {
            Tip.focus("limit", "请填写赠送余额次数!");
            return false;
        }
        return true;
    }
</script>
{elseif $operation == 'record'}
     <form action="" method="post">
<div class="panel panel-default">
    <div class="panel-body table-responsive">
        <table class="table table-hover">
            <thead class="navbar-inner">
                <tr>
                    <th style="width:10%;">ID</th>
                    <th style='width:10%'>领取余额数</th>
                    <th style='width:40%'>领取时间</th>
                    <th style='width:40%'>领取人</th>
                </tr>
            </thead>
            <tbody>
                {loop $record $row}
                <tr>
                    <td>{$row['id']}</td>
                    <td>{$row['num']}</td>
                    <td>{$row['createtime']}</td>
                    <td>{$row['nickname']}</td>
                </tr>
                {/loop}
            </tbody>
        </table>
        {$pager}
    </div>
</div>
</form>
<script>
    require(['bootstrap'], function ($) {
        $('.btn').hover(function () {
            $(this).tooltip('show');
        }, function () {
            $(this).tooltip('hide');
        });
    });
</script>
{elseif $operation == 'qrcode'}
<div class="main">
    <form     {ife 'saoyue.list' $saoyue}action="" method="post"{/if} class="form-horizontal form" enctype="multipart/form-data" onsubmit='return formcheck()'>
        <div class="panel panel-default">
            <div class="panel-heading">
               批量二维码设置
            </div>
            <div class="panel-body">
            	<div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">批量生成二维码ID</label>
                    <div class="col-sm-9 col-xs-12">
                    <div class="form-control" style="border:0">{$_GPC['id']}</div>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style="color:red">*</span>回复规则名称</label>
                    <div class="col-sm-9 col-xs-12">
                        <input type="text" id='name' name="name" class="form-control" value="" />
                        <span class="help-block">系统会自动生成一组名称+ID，以区分每一个规则和二维码</span>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style="color:red">*</span>触发关键字</label>
                    <div class="col-sm-9 col-xs-12">
                        <input type="text" id='keyword' name="keyword" class="form-control" value="" />
                        <span class="help-block">系统会自动生成一组关键字+ID，以区分每一个推送消息</span>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style="color:red">*</span>图文消息标题</label>
                    <div class="col-sm-9 col-xs-12">
                        <input type="text" id='title' name="title" class="form-control" value="" />
                    </div>
                </div>
                <div class="form-group">
				    <label class="col-xs-12 col-sm-3 col-md-2 control-label">封面</label>
				    <div class="col-sm-9 col-xs-12">
				        {php echo tpl_form_field_image('thumb', '')}
				        <span class="help-block">封面，建议尺寸: 360像素 * 200像素 </span>
				    </div>
				</div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">描述</label>
                    <div class="col-sm-9 col-xs-12">
                        <input type="text" id='description' name="description" class="form-control" value="" />
                        <span class="help-block">添加图文消息的简短描述</span>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style="color:red">*</span>需要生成二维码数量</label>
                    <div class="col-sm-9 col-xs-12">
                        <input type="text" id='number' name="number" class="form-control" value="" />
                        <span class="help-block"></span>
                    </div>
                </div>
                <div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">二维码类型</label>
					<div class="col-sm-9 col-xs-12">
						<label for="radio_1" class="radio-inline"><input type="radio" name="qrc-model" id="radio_1" onclick="$('#model2').hide();$('#model1').show();" value="1" checked="checked"/> 临时</label>
						<label for="radio_0" class="radio-inline"><input type="radio" name="qrc-model" id="radio_0" onclick="$('#model1').hide();$('#model2').show();" value="2"  /> 永久</label>
						<span class="help-block">目前有2种类型的二维码, 分别是临时二维码和永久二维码, 前者有过期时间, 但能够生成较多数量, 后者无过期时间, 数量较少(目前参数只支持1--100000).</span>
					</div>
				</div>
				<div class="form-group" id="model1">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">过期时间</label>
					<div class="col-sm-9 col-xs-12">
						{php echo tpl_form_field_daterange('time', array('start'=>date('Y-m-d H:i:s',time()),'end'=>date('Y-m-d H:i:s',time()+604800)), true)}
			            <div class="help-block">输入二维码起止时间</div>
					</div>
				</div>
				<div class="form-group" id="model2" style="display:none;">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">场景值</label>
					<div class="col-sm-9 col-xs-12">
						<input type="text" class="form-control" placeholder="场景值" id="scene_str" name="scene_str" value="{$row['scene_str']}" />
						<span class="help-block">场景值不能重复，只能是字符串或汉字，不能是数字，仅永久二维码支持。<strong class="text-danger">此处可为空</strong></span>
					</div>
				</div>
				
                <div class="form-group"></div>
            	<div class="form-group">
                	<label class="col-xs-12 col-sm-3 col-md-2 control-label"></label>
                	<div class="col-sm-9 col-xs-12">
                       	<input type="submit" name="submit" value="提交" class="btn btn-primary col-lg-1"  />
                        <input type="hidden" name="token" value="{$_W['token']}" />
                   		<input type="button" name="back" onclick='history.back()' style='margin-left:10px;' value="返回列表" class="btn btn-default" />
                	</div>
            	</div>
            </div>
        </div>
    </form>
</div>
<script language='javascript'>
    function formcheck() {
        if ($("#name").isEmpty()) {
            Tip.focus("name", "请填写回复规则名称!");
            return false;
        }
        if ($("#keyword").isEmpty()) {
            Tip.focus("keyword", "请填写触发关键字!");
            return false;
        }
        if ($("#title").isEmpty()) {
            Tip.focus("title", "请填写图文消息标题!");
            return false;
        }
        if ($("#number").isEmpty()) {
            Tip.focus("number", "请填写需要生成二维码的数量!");
            return false;
        }
        return true;
    }
</script>
{elseif $operation == 'download'}
<form action="" method="post">
<div class="panel panel-default">
    <div class="panel-body table-responsive">
        <table class="table table-hover">
            <thead class="navbar-inner">
                <tr>
                    <th style="width:10%">ID</th>
                    <th style="width:30%">名称</th>
                    <th style="width:20%">创建时间</th>
                    <th style='width:40%'>操作</th>
                </tr>
            </thead>
            <tbody>
                {loop $list $row}
                <tr>
                    <td style="width:10%">{$row['id']}</td>
                    <td style='width:30%'>{$row['name']}</td>
                    <td style='width:20%'>{$row['createtime']}</td>
                    <td style="text-align:left;width:40%">
                    	<a href="{$row['downlink']}" class="btn btn-default btn-sm">
                       	下载压缩包</a>
                        <a href="{$row['deletelink']}" 
                        	class="btn btn-default btn-sm" onclick="return confirm('确认删除此压缩包?')" title="删除"><i class="fa fa-times"></i>删除压缩包
                       	</a>
                    </td>
                </tr>
                {/loop}
            </tbody>
        </table>
        {$pager}
    </div>
</div>
</form>
{/if}
{template 'web/_footer'}